package com.gc.web.controller.business;

import cn.hutool.core.date.DateUtil;
import com.gc.business.domain.InventorySizePrice;
import com.gc.business.service.IInventorySizePriceService;
import com.gc.common.base.Result;
import com.gc.common.support.Convert;
import com.gc.common.utils.poi.ExcelUtil;
import com.gc.framework.util.ShiroUtils;
import com.gc.framework.web.base.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 库存规格值 控制层
 * 
 * @author hruiyan
 * @date 2020-11-10
 */
@Slf4j
@Controller
@RequestMapping("/business/inventorySizePrice")
public class InventorySizePriceController extends BaseController {
    private String prefix = "business/inventorySizePrice";
	
	private final IInventorySizePriceService inventorySizePriceService;

	@Autowired
	public InventorySizePriceController(IInventorySizePriceService inventorySizePriceService) {
		this.inventorySizePriceService = inventorySizePriceService;
	}

	/**
	*  列表页
	*/
	//@RequiresPermissions("business:inventorySizePrice:view")
	@GetMapping
	public String inventorySizePrice(Long sizeId,ModelMap mmap){
		mmap.put("sizeId",sizeId);
	    return prefix + "/inventorySizePrice";
	}

	/**
	 * 新增页
	 */
	@GetMapping("/add")
	public String add(Long sizeId,ModelMap mmap){
		mmap.put("sizeId",sizeId);
		return prefix + "/add";
	}

	/**
	 * 编辑页
	 */
	@GetMapping("/edit/{priceId}")
	public String edit(@PathVariable("priceId") Long priceId, ModelMap mmap){
		InventorySizePrice inventorySizePrice = inventorySizePriceService.getById(priceId);
		mmap.put("inventorySizePrice", inventorySizePrice);
		return prefix + "/edit";
	}
	
	/**
	 * 查询库存规格值列表
	 */
	//@RequiresPermissions("business:inventorySizePrice:list")
	@PostMapping("/list")
	@ResponseBody
	public Result list(InventorySizePrice inventorySizePrice){
		startPage();
        List<InventorySizePrice> list = inventorySizePriceService.list(inventorySizePrice);
		return Result.success(getDataTable(list));
	}

	/**
	 * 新增保存库存规格值
	 */
	//@RequiresPermissions("business:inventorySizePrice:add")
	//@Log(title = "库存规格值", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public Result addSave(InventorySizePrice inventorySizePrice){
		inventorySizePrice.setCreateBy(ShiroUtils.getSysUser().getUserName());
		inventorySizePrice.setCreateTime(DateUtil.date());
		inventorySizePriceService.save(inventorySizePrice);
		return Result.success();
	}

	/**
	 * 修改保存库存规格值
	 */
	//@RequiresPermissions("business:inventorySizePrice:edit")
	//@Log(title = "库存规格值", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public Result editSave(InventorySizePrice inventorySizePrice){
		inventorySizePriceService.updateById(inventorySizePrice);
		return Result.success();
	}
	
	/**
	 * 删除库存规格值
	 */
	//@RequiresPermissions("business:inventorySizePrice:remove")
	//@Log(title = "库存规格值", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public Result remove(String ids){
		Long[] longIds = Convert.toLongArray(ids);
		inventorySizePriceService.removeByIds(Arrays.asList(longIds));
		return Result.success();
	}

	/**
	 * 导出库存规格值列表
	 */
	//@RequiresPermissions("business:inventorySizePrice:export")
	@PostMapping("/export")
	@ResponseBody
	public Result export(InventorySizePrice inventorySizePrice){
		List<InventorySizePrice> list = inventorySizePriceService.list(inventorySizePrice);
		ExcelUtil<InventorySizePrice> util = new ExcelUtil<>(InventorySizePrice.class);
		util.exportExcel(list, "inventorySizePrice");
		return Result.success();
	}
}
